package admin

import (
	"duoke/service"
	"duoke/utils/gconv"
	"duoke/utils/request"
	"duoke/utils/response"
	"github.com/gin-gonic/gin"
)

var Setting = new(settingCtl)

type settingCtl struct{}

// 获取设置信息
func (ctl *settingCtl) Info(c *gin.Context) {
	req := request.JsonMap(c)
	if req["field"] == "" {
		response.Error(c, "field缺失", nil)
		return
	}
	info, err := service.AccountSetting.Info(c, gconv.String(req["field"]))
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "", info)
}

// 设置保存
func (ctl *settingCtl) Save(c *gin.Context) {
	req := request.JsonMap(c)
	if req["field"] == "" || req["data"] == "" {
		response.Error(c, "field/data数据缺失", nil)
		return
	}
	err := service.AccountSetting.Save(c, req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "保存成功", nil)
}
